"""
    用户类


"""
from Dao.SuperDBManager import SuperDBManager
from Dao.DataBase import sqlite_connect
from Chara.CharaLoader import CharaFactory

cf = CharaFactory()
class UserMangerError(Exception):
    def __init__(self,tb):
        super(UserMangerError, self).__init__(tb)

class MyUser:
    def __init__(self, userName):
        self.userName = userName
        self.userDas = SuperDBManager.findByDict("UserInfo.db3", "UserInfo", {"用户名": userName})
        self.userDas = self.userDas[0] if self.userDas != [] else self.userDas
        if self.userDas == []:
            raise UserMangerError("错误数据！")
        print(self.userDas)
        *self.pwd, self.ExamCount, self.useChara, self.money, self.headImage = self.userDas


    def flushed(self):
        """
        刷新用户数据数据
        @return:
        """
        self.__init__(self.userName)

    @staticmethod
    def change_after_flushed(func):
        """
        用户数据刷新装饰器
        @param func:
        @return:
        """
        def inner(username):
            func()
            MyUser(userName=username).flushed()
        return inner

if __name__ == '__main__':

    @MyUser.change_after_flushed
    def test():
        print("xxx")
    test('p')

